package com.ambow.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ambow.Entity.Cell;
import com.ambow.Entity.Supplier;
import com.ambow.service.CellService;
import com.ambow.service.SupplierService;
import com.ambow.service.impl.CellServiceImpl;
import com.ambow.service.impl.SupplierServiceImpl;

/**
 * Servlet implementation class SupplierServlet
 */
@WebServlet("/SupplierServlet")
public class SupplierServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
     SupplierService supplierService=new SupplierServiceImpl();
     CellService cellService=new CellServiceImpl();
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String status=request.getParameter("status");
		if(status.equals("query")) {
			query(request,response);
		}
	
	}
      //查询所有的供应商信息和架位信息
	private void query(HttpServletRequest request, HttpServletResponse response) {
	   List<Supplier> supplierList=supplierService.query("from Supplier", null);
	   List<Cell> cellList=cellService.queryAll("from Cell", null);
	    request.getSession().setAttribute("cellList", cellList);
	   request.getSession().setAttribute("supplierList", supplierList);
	   System.out.println("supplierList的长度："+supplierList.size());
	   System.out.println("cellList的长度："+cellList.size());
	   try {
		request.getRequestDispatcher("pages/module/storage/storage002/receive.jsp").forward(request, response);
	} catch (ServletException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
		
	}

}
